<?=form_open(uri_string(),array('id'=>'fr_view'))?>

<table width="100%" class="form">
    <tr>
        <td  class="label">Người gởi</td>
        <td><?=$rs->lb_cusname?><br /><?=$rs->lb_cusmail?></td>
    </tr>

    <tr>
        <td class="label">Chủ đề :</td>
        <td><?=$rs->lb_subject?></td>
    </tr>
    <?php if(!empty($rs->lb_content_vn)){?>
    <tr>
        <td class="label">Nội dung :</td>
        <td style="text-align:justify;"><?=$rs->lb_content_vn?></td>
    </tr>
    <?php }?>
    <?php if(!empty($rs->lb_content_en)){?>
    <tr>
        <td class="label">Nội dung :</td>
        <td style="text-align:justify;"><?=$rs->lb_content_en?></td>
    </tr>
     <?php }?>
    <tr>
        <td class="label">Ngày gởi :<br />Trạng thái :</td>
        <td><?=datevn($rs->dt_create)?><br /><?=$rs->is_read? 'Đã xem':'';?></td>
    </tr>
   
    <tr>
        <td class="label"></td>
        <td ><?php if($rs->is_question==1) echo  '<button id="traloi">Trả lời</button>';?></td>
    </tr>
    <tr class="fr_show_hidden">
        <td class="label">Người gửi:</td>
        <input type="hidden" value="<?php echo $rs->tv_id;?>" name="tv_id" id="tv_id">
        <td><input type="text"  name="cusname" id="cusname"></td>
    </tr>
    <?php if($rs->lb_content_vn){?>
    <tr class="fr_show_hidden">
        <td class="label">Nội dung Trả lời:</td>
        <td><textarea id="noidung_vn" name="noidung_vn"></textarea></td>
    </tr>
    <?php }elseif($rs->lb_content_en){ ?>
    <tr class="fr_show_hidden">
        <td class="label">Nội dung Trả lời(t.anh):</td>
        <td><textarea id="noidung_en" name="noidung_en"></textarea></td>
    </tr>
   <?php } ?>
    <tr class="fr_show_hidden" >
        <td class="label"></td>
        <td><input type="submit" name="bt_submit" id="bt_submit" value="Send"></td>
    </tr>
    <!--<tr>
        <td colspan="2" align="center"><input type="submit" name="bt_submit" value="Cập nhật" class="capnhat"></td>
    </tr>-->
</table>
<?=form_close()?>
<script>
$(document).ready(function(){
	
	$('#bt_submit').click(function(){
		$('#fr_view').submit(function(){
			cusname=$('#cusname').val();
			tv_id=$('#tv_id').val();
			noidung_vn=$('#noidung_vn').val();
			noidung_en=$('#noidung_en').val();
			$.ajax({
				type:"POST",
				data:({'tv_id':tv_id,'noidung_vn':noidung_vn,'noidung_en':noidung_en,'cusname':cusname}),
				url:url+"tuvan/anser",
				success: function(data){
					if(data==1){
						alert('Trả lời thành công');
						$('#noidung_vn').val('');
						$('#noidung_en').val('');
						$('.fr_show_hidden').hide();
						window.location.href=url+'tuvan';	
					}
					else
						alert('Trả lời thất bại');	
				}
			});
			return false;
		});
	});
	
	$('.fr_show_hidden').hide();
		
	$('#traloi').toggle(
		function(){
				$('.fr_show_hidden').show();
		},function(){
				$('.fr_show_hidden').hide();
		}
	);
});
</script>